(function($){
    function initAddPhoto() {
        var but = $('#but_add_photo');
        but.on('click', function(){
            //判断数量不能大于8
            if($('#answer_pic_box input').size() >= 8) {
                layer.alert('最多只能上传8张图片！');
                return;
            }
            var box = $('#answer_pic_box');
            box.append('<div class="input-group paddingTB5"><input type="file" class="form-control" name="answer_pic[]"><div class="input-group-addon bg_red cursor_pointer" onclick="$.bpPhotoDel(this)"><i class="fa fa-times"></i></div></div>');
        });
    }
    function setFormResult(msg, state) {
        layer.closeAll();
        if(state == 0) {
            layer.alert(msg, {icon: 5});
        } else {
            layer.alert('回答问题成功！', function(index){
                parent.location.reload();
            });
        }
    }
    $(function(){
        initAddPhoto();
        window.setFormResult = setFormResult;
        $('#form_add').on('valid.form', function(e, form){
            layer.load();
            form.submit();
        });
        $.extend({
            'bpPhotoDel': function(obj) {
                $(obj).parent().remove();
            }
        });
    });
})(jQuery);